package com.akuhome.resource.service.entity;

import com.akuhome.resource.dao.ClassroomDao;
import com.akuhome.resource.entity.Classroom;
import com.akuhome.resource.enums.ResultEnum;
import com.akuhome.resource.exception.ResourceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassroomService {
    @Autowired
    ClassroomDao classroomDao;

    public List<Classroom> findAllClassroom(){
        return classroomDao.findAllClassroom();
    }

    public Integer insertClassroom(Classroom classroom){
        int row = classroomDao.insertClassroom(classroom);
        if(row == 1) {
            return classroom.getId();
        }else{
            throw new ResourceException(ResultEnum.ARG_MISMATCH_ERROR);
        }
    }
    public Object updateClassroom(Classroom classroom){
        int row = classroomDao.updateClassroom(classroom);
        if(row == 1) {
            return null;
        }else if(row == 0){
            throw new ResourceException(ResultEnum.ARG_MISMATCH_ERROR);
        }else{
            throw new ResourceException(ResultEnum.UNKNOWN_ERROR);
        }
    }
    public Object deleteClassroomById(Integer classroomId){
        int row = classroomDao.deleteClassroomById(classroomId);
        if(row == 1){
            return null;
        }else{
            throw new ResourceException(ResultEnum.ARG_MISMATCH_ERROR);
        }
    }
}
